package com.study;

import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

@Service
public class UserService {

    public static final List<User> USER_LIST = new ArrayList<>();
    static {
        User user = new User();
        user.setId(8L);
        user.setUsername("刘阿勇");
        user.setSex(Boolean.TRUE);  // true:男 false:女

        USER_LIST.add(user);
    }

    public List<User> list() {
        return  USER_LIST;
    }

    public Long save(User user) {
        if(ObjectUtils.isEmpty(user.getId())) {
            Random random = new Random();
            long l = random.nextInt(100000);
            user.setId(l);
        }
        USER_LIST.add(user);
        return  user.getId() ;
    }
}
